


$(function () {
    let hourPrice = new Array();
    let countHour = new Array();

    //接收后端产生

    $.get("/shop-admin/Data/analyse",function (data) {
        let parse = data;
        let dbData = parse.data;
        let sumPrice =0;
        let sumCount = 0;
        dbData.forEach(item=>{
            hourPrice.push(item.hourPrice);
            countHour.push(item.countHour);
            sumPrice+=item.hourPrice;
            sumCount+=item.countHour
        })


        $("#sumPrice").html("￥"+sumPrice.toFixed(2))
        $("#countHour").html(sumCount)
        $("#perPrice").html("￥"+(sumPrice/sumCount).toFixed(2))

        $(function () {
            $("#container").highcharts({
                chart: {
                    type: 'column',

                },
                title: {
                    text: null
                },
                yAxis: [{
                    className: 'highcharts-color-0',
                    title: {
                        text: '销售金额'
                    }
                }, {
                    className: 'highcharts-color-1',
                    opposite: true,
                    title: {
                        text: '支付订单'
                    },

                    labels:{
                        enable:true,
                        step:2
                    }

                }],
                plotOptions: {
                    column: {
                        borderRadius: 6
                    }
                },
                series: [{
                    name: '销售金额',
                    data: hourPrice,

                }, {
                    name: '支付订单',
                    data: countHour,
                    yAxis: 1

                }],


            })

        })
    })

})


$(function () {
    let views = new Array();
    let goodsViews = new Array();
    let viewsDate= new Array()
    //接收后端产生

    $.get("/shop-admin/Data/analyse1",function (data) {

        let parse = data;
        let dbData = parse.data;

        dbData.forEach(item=>{
            views.push(item.views);
            goodsViews.push(item.goodsViews);

            let da = new Date(item.viewsDate);
            let year = da.getFullYear();
            let month = da.getMonth()+1;
            let date = da.getDate();
            viewsDate.push([year,month,date].join('-'));

        })
        let todayGoodsViews = goodsViews[6];
        let todayViews=views[6];
        console.log(viewsDate);
        console.log(todayGoodsViews);
        console.log(todayViews);

        $("#views").html(todayViews)
        $("#goodsViews").html(todayGoodsViews)

        $(function () {

            $("#container1").highcharts({

                title: {
                    text: "七日浏览量/访问量"
                },
                xAxis: {
                    categories: viewsDate
                },
                yAxis: [{
                    title: {
                        text: '浏览量'
                    }
                }],
                series: [{
                    name: '浏览量',
                    data: goodsViews

                },
                    {
                        name: '访问量',
                        data: views

                    }],

                plotOptions: {
                    column: {
                        borderRadius: 6
                    }
                },

            })
        })
    })

})